#!/usr/local/python/bin/python
# coding=utf-8
__author__ = 'cz'

from tdtools import LogUtil
import tdtools.Config_tdsql_prd as config
from tdtools.HttpUtil import *
from tdtools.JsonExtUtils import *

_logger=LogUtil._logger
class DcpClient():
    @staticmethod
    def getUrl(appUrl):
        return config._url + appUrl

    # 获取文件基本信息
    def getFileInfo(self, bizCode):
        url = DcpClient.getUrl('getFileInfo')
        values = {'bizCode': bizCode}
        return HttpUtil.httpPost(url, values)

    # 获取应用服务信息
    def getDbInfo(self, dbCode):
        url = DcpClient.getUrl('getByDbCode')
        values = {'dbCode': dbCode}
        return HttpUtil.httpPost(url, values)

    # 获取应用服务信息
    def getAppInfo(self, dbCode, appCode):
        url = DcpClient.getUrl('getByDbCodeAndAppCode')
        values = {'dbCode': dbCode, 'appCode': appCode}
        return HttpUtil.httpPost(url, values)

    # 获取字段信息
    def getFileCols(self, bizCode):
        url = DcpClient.getUrl('getFileCols')
        values = {'bizCode': bizCode}
        return HttpUtil.httpPost(url, values)

    # 获取数据库链接信息
    def getDbConnInfo(self, pkId):
        url = DcpClient.getUrl('getDbConnInfo')
        values = {'pkId': pkId}
        return HttpUtil.httpPost(url, values)

    # 保存日志
    @staticmethod
    def saveLog(log):
        url = DcpClient.getUrl('saveLog')
        chgLog = JsonExtUtils.objToJson(log)
        return HttpUtil.httpPost(url, chgLog)

    # 保存操作日志
    @staticmethod
    def saveExecLog(log):
        url = DcpClient.getUrl('saveExecLog')
        chgLog = JsonExtUtils.objToJson(log)
        return HttpUtil.httpPost(url, chgLog)

    # 插入问题id数据
    def addProblemId(self, ID, appCode, bizCode, bizDate):
        url = DcpClient.getUrl('smsCheck/addProblemId')
        values = {'ID': ID, 'appCode': appCode, 'bizCode': bizCode, 'bizDate': bizDate}
        print (url)
        return HttpUtil.httpPost(url, values)

    # 获取业务日期下的等待任务
    def getTastWait(self,bizDate, tastStatus):
        url = DcpClient.getUrl('ctlTask/queryCtlTask?bizDate='+ bizDate +'&status=1&pageInex=0&pageSize=1000')
        values = {}
        print (url)
        return HttpUtil.httpPost2(url, values)


